﻿using MediatR;
using WMS.API.Application.Command.DeliveryOrderManagement.DeliveryOrder;
using WMS.API.Application.Command.StocktakingManagement;
using WMS.Domain.Entities.DeliveryOrderManagement;
using WMS.ErrorCode;
using WMS.Interfactructure.Interfaces;

namespace WMS.API.Application.CommandHandlers.DeliveryOrderManagement.DeliveryOrder
{
    public class QueryPendingFreightCommandHandler : IRequestHandler<QueryPendingFreightCommand, APIResult<List<PendingFreightModel>>>
    {
        private readonly IBaseRepository<PendingFreightModel> _pendfreightrepository;

        public QueryPendingFreightCommandHandler(IBaseRepository<PendingFreightModel> pendfreightrepository)
        {
           _pendfreightrepository = pendfreightrepository;
        }

        public Task<APIResult<List<PendingFreightModel>>> Handle(QueryPendingFreightCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<PendingFreightModel>> result=new APIResult<List<PendingFreightModel>>("查询待发货成功");
            result.Message = "查询待发货成功";
            result.Code = ResultCode.Success;
            var list = _pendfreightrepository.GetAll();
            //团队
            if (!string.IsNullOrEmpty(request.Team))
            {
                list=list.Where(x=>x.Team==request.Team);
            }
            //运单号
            if (!string.IsNullOrEmpty(request.TrackingNumber))
            {
                list = list.Where(x => x.TrackingNumber == request.TrackingNumber);
            }
            //出库单号
            if (!string.IsNullOrEmpty(request.ShippingNumber))
            {
                list = list.Where(x => x.ShippingNumber == request.ShippingNumber);
            }
            //出库单号
            if (!string.IsNullOrEmpty(request.WarehouseName))
            {
                list = list.Where(x => x.WarehouseName == request.WarehouseName);
            }
            result.Data=list.ToList();

            return Task.FromResult(result);
        }

       
    }
}
